From 9726237543394a5cf7b96bd76a9ccdcbe075e7e6 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Tue, 27 Mar 2007 15:53:45 +0100 Subject: [PATCH] Add WARN() and generic WARN_ON(). Based on a patch by Jan Beulich Signed-off-by: Keir Fraser --- xen/arch/ia64/linux-xen/mca.c | 10 --------- xen/arch/powerpc/backtrace.c | 15 ------------- xen/arch/x86/traps.c | 22 +++++++++++++------- xen/drivers/char/console.c | 10 +++++++-- xen/include/asm-ia64/bug.h | 1 + xen/include/asm-ia64/linux-xen/asm/iosapic.h | 7 ------- xen/include/asm-powerpc/bug.h | 1 + xen/include/asm-powerpc/debugger.h | 4 ---- xen/include/asm-x86/bug.h | 6 +++--- xen/include/asm-x86/x86_32/bug.h | 6 ++++++ xen/include/asm-x86/x86_64/bug.h | 6 ++++++ xen/include/xen/lib.h | 4 +++- 12 files changed, 42 insertions(+), 50 deletions(-) diff --git a/xen/arch/ia64/linux-xen/mca.c b/xen/arch/ia64/linux-xen/mca.c index f1f47c68e2..68fa284e2d 100644 --- a/xen/arch/ia64/linux-xen/mca.c +++ b/xen/arch/ia64/linux-xen/mca.c @@ -396,16 +396,6 @@ ia64_log_queue(int sal_info_type, int virq) #ifdef CONFIG_ACPI #ifdef XEN -/** - * Copy from linux/include/asm-generic/bug.h - */ -#define WARN_ON(condition) do { \ - if (unlikely((condition)!=0)) { \ - printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \ - dump_stack(); \ - } \ -} while (0) - /** * Copy from linux/kernel/irq/manage.c * diff --git a/xen/arch/powerpc/backtrace.c b/xen/arch/powerpc/backtrace.c index badbd9d2e5..7cf8032af7 100644 --- a/xen/arch/powerpc/backtrace.c +++ b/xen/arch/powerpc/backtrace.c @@ -205,21 +205,6 @@ void show_backtrace_regs(struct cpu_user_regs *regs) console_end_sync(); } -void __warn(char *file, int line) -{ - ulong sp; - ulong lr; - - console_start_sync(); - printk("WARN at %s:%d\n", file, line); - - sp = (ulong)__builtin_frame_address(0); - lr = (ulong)__builtin_return_address(0); - backtrace(sp, lr, lr); - - console_end_sync(); -} - void dump_execution_state(void) { struct cpu_user_regs *regs = guest_cpu_user_regs(); diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 2423ad5493..bab363e747 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -637,29 +637,35 @@ asmlinkage int do_invalid_op(struct cpu_user_regs *regs) memcmp(bug.ud2, "\xf\xb", sizeof(bug.ud2)) || (bug.ret != 0xc2) ) goto die; + eip += sizeof(bug); id = bug.id & 3; - if ( id == BUGFRAME_rsvd ) - goto die; if ( id == BUGFRAME_dump ) { show_execution_state(regs); - regs->eip += sizeof(bug); + regs->eip = (unsigned long)eip; return EXCRET_fault_fixed; } - /* BUG() or ASSERT(): decode the filename pointer and line number. */ - ASSERT((id == BUGFRAME_bug) || (id == BUGFRAME_assert)); - eip += sizeof(bug); + /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ if ( !is_kernel(eip) || __copy_from_user(&bug_str, eip, sizeof(bug_str)) || memcmp(bug_str.mov, BUG_MOV_STR, sizeof(bug_str.mov)) ) goto die; + eip += sizeof(bug_str); filename = is_kernel(bug_str.str) ? (char *)bug_str.str : ""; lineno = bug.id >> 2; + if ( id == BUGFRAME_warn ) + { + printk("Xen WARN at %.50s:%d\n", filename, lineno); + show_execution_state(regs); + regs->eip = (unsigned long)eip; + return EXCRET_fault_fixed; + } + if ( id == BUGFRAME_bug ) { printk("Xen BUG at %.50s:%d\n", filename, lineno); @@ -668,13 +674,13 @@ asmlinkage int do_invalid_op(struct cpu_user_regs *regs) panic("Xen BUG at %.50s:%d\n", filename, lineno); } - /* ASSERT(): decode the predicate string pointer. */ + /* ASSERT: decode the predicate string pointer. */ ASSERT(id == BUGFRAME_assert); - eip += sizeof(bug_str); if ( !is_kernel(eip) || __copy_from_user(&bug_str, eip, sizeof(bug_str)) || memcmp(bug_str.mov, BUG_MOV_STR, sizeof(bug_str.mov)) ) goto die; + eip += sizeof(bug_str); predicate = is_kernel(bug_str.str) ? (char *)bug_str.str : ""; printk("Assertion '%s' failed at %.50s:%d\n", diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index ef11d735ba..87786f152f 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -900,12 +900,18 @@ void panic(const char *fmt, ...) void __bug(char *file, int line) { console_start_sync(); - printk("BUG at %s:%d\n", file, line); + printk("Xen BUG at %s:%d\n", file, line); dump_execution_state(); - panic("BUG at %s:%d\n", file, line); + panic("Xen BUG at %s:%d\n", file, line); for ( ; ; ) ; } +void __warn(char *file, int line) +{ + printk("Xen WARN at %s:%d\n", file, line); + dump_execution_state(); +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-ia64/bug.h b/xen/include/asm-ia64/bug.h index 2caf275c39..a13a76bf8c 100644 --- a/xen/include/asm-ia64/bug.h +++ b/xen/include/asm-ia64/bug.h @@ -2,5 +2,6 @@ #define __IA64_BUG_H__ #define BUG() __bug(__FILE__, __LINE__) +#define WARN() __warn(__FILE__, __LINE__) #endif /* __IA64_BUG_H__ */ diff --git a/xen/include/asm-ia64/linux-xen/asm/iosapic.h b/xen/include/asm-ia64/linux-xen/asm/iosapic.h index f289349ea0..a94e5f53da 100644 --- a/xen/include/asm-ia64/linux-xen/asm/iosapic.h +++ b/xen/include/asm-ia64/linux-xen/asm/iosapic.h @@ -123,13 +123,6 @@ static inline void list_move(struct list_head *list, struct list_head *head) #define move_irq(x) -#define WARN_ON(condition) do { \ - if (unlikely((condition)!=0)) { \ - printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \ - dump_stack(); \ - } \ -} while (0) - #ifdef nop #undef nop #endif diff --git a/xen/include/asm-powerpc/bug.h b/xen/include/asm-powerpc/bug.h index 20d7d4bfb9..65caa37171 100644 --- a/xen/include/asm-powerpc/bug.h +++ b/xen/include/asm-powerpc/bug.h @@ -2,5 +2,6 @@ #define __POWERPC_BUG_H__ #define BUG() __bug(__FILE__, __LINE__) +#define WARN() __warn(__FILE__, __LINE__) #endif /* __POWERPC_BUG_H__ */ diff --git a/xen/include/asm-powerpc/debugger.h b/xen/include/asm-powerpc/debugger.h index 4e4cea5df2..8a979d0e11 100644 --- a/xen/include/asm-powerpc/debugger.h +++ b/xen/include/asm-powerpc/debugger.h @@ -67,10 +67,6 @@ static inline void unimplemented(void) #endif } -extern void __warn(char *file, int line); -#define WARN() __warn(__FILE__, __LINE__) -#define WARN_ON(_p) do { if (_p) WARN(); } while ( 0 ) - extern void __attn(void); #define ATTN() __attn(); diff --git a/xen/include/asm-x86/bug.h b/xen/include/asm-x86/bug.h index d09e3ea7a0..975576185c 100644 --- a/xen/include/asm-x86/bug.h +++ b/xen/include/asm-x86/bug.h @@ -14,8 +14,8 @@ struct bug_frame { } __attribute__((packed)); #define BUGFRAME_dump 0 -#define BUGFRAME_bug 1 -#define BUGFRAME_assert 2 -#define BUGFRAME_rsvd 3 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 #endif /* __X86_BUG_H__ */ diff --git a/xen/include/asm-x86/x86_32/bug.h b/xen/include/asm-x86/x86_32/bug.h index 9e2c4ce695..20a9137063 100644 --- a/xen/include/asm-x86/x86_32/bug.h +++ b/xen/include/asm-x86/x86_32/bug.h @@ -12,6 +12,12 @@ struct bug_frame_str { "ud2 ; ret $%c0" \ : : "i" (BUGFRAME_dump) ) +#define WARN() \ + asm volatile ( \ + "ud2 ; ret $%c0 ; .byte 0xbc ; .long %c1" \ + : : "i" (BUGFRAME_warn | (__LINE__<<2)), \ + "i" (__FILE__) ) + #define BUG() \ asm volatile ( \ "ud2 ; ret $%c0 ; .byte 0xbc ; .long %c1" \ diff --git a/xen/include/asm-x86/x86_64/bug.h b/xen/include/asm-x86/x86_64/bug.h index 5676f3878c..3fa5debfa7 100644 --- a/xen/include/asm-x86/x86_64/bug.h +++ b/xen/include/asm-x86/x86_64/bug.h @@ -12,6 +12,12 @@ struct bug_frame_str { "ud2 ; ret $%c0" \ : : "i" (BUGFRAME_dump) ) +#define WARN() \ + asm volatile ( \ + "ud2 ; ret $%c0 ; .byte 0x48,0xbc ; .quad %c1" \ + : : "i" (BUGFRAME_warn | (__LINE__<<2)), \ + "i" (__FILE__) ) + #define BUG() \ asm volatile ( \ "ud2 ; ret $%c0 ; .byte 0x48,0xbc ; .quad %c1" \ diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index f5f59441f1..3145542b25 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -10,8 +10,10 @@ #include void __bug(char *file, int line) __attribute__((noreturn)); +void __warn(char *file, int line); -#define BUG_ON(_p) do { if (_p) BUG(); } while ( 0 ) +#define BUG_ON(p) do { if (p) BUG(); } while (0) +#define WARN_ON(p) do { if (p) WARN(); } while (0) /* Force a compilation error if condition is true */ #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) -- 2.30.2